//
//  LYChatsubModel.swift
//  WeChat
//
//  Created by mac on 2018/8/14.
//  Copyright © 2018年 RRC. All rights reserved.
//

import Foundation
import SwiftyJSON

/**
 *聊天内的子 model，根据字典返回类型做处理
 */
class ChatAudioModel: NSObject {
    var audioId:String?
    var audioURL:String?
    var bitRate:String?
    var channels:String?
    var createTime:String?
    var duration:Float?
    var fileSize:String?
    var formatName:String?
    var keyHash:String?
    var mimeType:String?
    
    override init() {
        super.init()
    }
    
    func mapping(map:JSON) -> ChatAudioModel {
        audioId = map["audio_id"].stringValue
        audioURL = map["audio_url"].stringValue
        bitRate = map["bit_rate"].stringValue
        channels = map["channels"].stringValue
        createTime = map["ctime"].stringValue
        duration = map["duration"].floatValue
        fileSize = map["file_size"].stringValue
        formatName = map["format_name"].stringValue
        keyHash = map["key_hash"].stringValue
        mimeType = map["mime_type"].stringValue
        return self
    }
    
}


class ChatImageModel: NSObject {
    
    var imageHeight : CGFloat?
    var imageWidth : CGFloat?
    var imageId : String?
    var originalURL : String?
    var thumbURL : String?
    var localStoreName : String? //拍照，选择相机的图片的临时名称
    var localThumbnailImage : UIImage?{ //从 Disk 加载出来的图片
        if let theLocalStoreName = localStoreName {
            let path = ImageFilesManager.cachePathForKey(theLocalStoreName)
            return UIImage(contentsOfFile: path!)
        }else{
            return nil
        }
    }
    
    override init() {
        super.init()
    }
    
    func modelWithJson(map:JSON) -> ChatImageModel{
        imageHeight = CGFloat(Int(map["height"].stringValue)!)
        imageWidth = CGFloat(Int(map["width"].stringValue)!)
        originalURL = map["original_url"].stringValue
        thumbURL = map["thumb_url"].stringValue
        imageId = map["image_id"].stringValue
        return self
    }
    
}

